<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Stict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-
strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title></title>
		<script src="../jss/global.js" type="text/javascript" charset="utf-8"></script>
		</head>

<body>
	<!-- 模糊查询 -->
		<div class="layui-form-item" style="margin-top: 20px;" onsubmit="return false;">
			<form class="layui-form">
				<label class="layui-form-mid">学生姓名:</label>
				<div class="layui-input-inline" style="width:120px;">
					<input type="text" id="studNameC" name="studName" autocomplete="off" class="layui-input">
				</div>
				<label class="layui-form-mid">电话:</label>
				<div class="layui-input-inline" style="width:120px;">
					<input type="text" id="studTelC" name="studTel" autocomplete="off" class="layui-input">
				</div>
				<label class="layui-form-mid">咨询师:</label>
				<div class="layui-input-inline" style="width:120px;">
					<select name="userName" id="userNameC">
					</select>
				</div>
				<label class="layui-form-mid">QQ:</label>
				<div class="layui-input-inline" style="width:120px;">
					<input type="text" id="studQqC" name="studQq" autocomplete="off" class="layui-input">
				</div>
				<label class="layui-form-mid">是否条件:</label>
				<div class="layui-input-inline" style="width:120px;">
					<select name="ynTerm" id="ynTermC">
						<option value=""></option>
						<option value=""></option>
						<option value=""></option>
						<option value=""></option>
						<option value=""></option>
						<option value=""></option>
						<option value=""></option>
						<option value=""></option>
					</select>
				</div>
				<label class="layui-form-mid">是否:</label>
				<div class="layui-input-inline" style="width:120px;">
					<select name="yesNo" id="yesNoC">
						<option value=""></option>
						<option value=""></option>
						<option value=""></option>
					</select>
				</div>
				<label class="layui-form-mid">时间类型:</label>
				<div class="layui-input-inline" style="width:120px;">
					<select name="timeType" id="timeTypeC">
						<option value=""></option>
						<option value=""></option>
						<option value=""></option>
						<option value=""></option>
						<option value=""></option>
						<option value=""></option>
					</select>
				</div>
				<label class="layui-form-mid">时间:</label>
				<div class="layui-input-inline" style="width:120px;">
					<input type="text" name="beginTime" id="beginTimeC" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
				</div>
				<label class="layui-form-mid">--</label>
				<div class="layui-input-inline" style="width:120px;">
					<input type="text" name="endTime" id="endTimeC" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
				</div>
			</form>
			<button class="layui-btn" id="search" data-type="reload">搜索</button>
			<input class="layui-btn" style="background-color:deepskyblue;" type="reset" value="重置"/>
		</div>

		<table class="layui-hide" id="demo" lay-filter="test"></table>

		<!--行内工具栏-->
		<script type="text/html" id="barDemo">
			<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="setRoleAction">查看</a>
			<a class="layui-btn layui-btn-xs" lay-event="setUserEdit">编辑</a>
			<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="setUserDel">删除</a>
			<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="setResetPwd">跟踪</a>
			<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="setResetPwd">跟踪记录</a>
		</script>
		

		<!--
        	作者：offline
        	时间：2019-06-24
        	描述：编辑
        -->
		<div id="yh_edit" style="display:none;margin-top: 20px;">
			<form class="layui-form" lay-filter="updateUser" action="">
				<div class="layui-form-item">
					<label class="layui-form-label">登录名:</label>
					<div class="layui-input-inline" style="width:350px;">
						<input type="hidden" id="userId" name="userId" class="layui-input" readonly="true">
						<input type="text" id="userName" name="userName" class="layui-input" readonly="true">
					</div>

				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">邮箱:</label>
					<div class="layui-input-inline" style="width:350px;">
						<input type="text" id="ProtectEMail" name="userEmail" required="" lay-verify="email" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">手机号:</label>
					<div class="layui-input-inline" style="width:350px;">
						<input type="text" id="ProtectMTel" name="userTel" required="" lay-verify="required|phone" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-btn-container" style="text-align:center;">
					<button class="layui-btn" lay-filter="userEditBtu" lay-submit="">
                        	修改
                    </button>
				</div>
			</form>
		</div>

		<!--查看页面-->
		<div id="user_add" style="display:none;margin-top: 20px;">
			<form id="formCreateUser" class="layui-form" action="">
				<div class="layui-form-item">
					<label class="layui-form-label"><span style="color: red;">*</span>登录名:</label>
					<div class="layui-input-inline" style="width:350px;">
						<input type="text" id="LoginName" placeholder="请输入用户名" name="userName" lay-verify="required" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label"><span style="color: red;">*</span>密码:</label>
					<div class="layui-input-inline" style="width:350px;">
						<input type="password" id="userpwd" name="userPassword" placeholder="请输入密码" lay-verify="required" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label"><span style="color: red;">*</span>邮箱:</label>
					<div class="layui-input-inline" style="width:350px;">
						<input type="text" id="ProtectEMail" name="userEmail" placeholder="请输入邮箱" lay-verify="email" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label"><span style="color: red;">*</span>手机号:</label>
					<div class="layui-input-inline" style="width:350px;">
						<input type="text" id="ProtectMTel" name="userTel" placeholder="请输入手机号" lay-verify="required|phone" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label"><span style="color: red;">*</span>权重:</label>
					<div class="layui-input-inline" style="width:350px;">
						<input type="text" id="userWeight" name="userWeight" placeholder="请输入权重" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-btn-container" style="text-align:center;">
					<button class="layui-btn" id="transmit" lay-submit="" lay-filter="adduser">添加</button>
				</div>
			</form>
		</div>
		<!--
        	作者：offline
        	时间：2019-06-24
        	描述：角色
        -->
		<div id="yh_role" style="display:none">
			<div id="role_transfer" class="demo-transfer"></div>

		</div>
		<script>
			layui.config({
				version: '1560414887305' //为了更新 js 缓存，可忽略
			});
			var loadCurr = false;
			layui.use(['laydate', 'layer', 'table', 'form', 'transfer'], function() {
				var laydate = layui.laydate //日期
					,
					layer = layui.layer //弹层
					,
					table = layui.table //表格
					,
					form = layui.form //轮播
					,
					transfer = layui.transfer; //滑块
					var $=layui.$;
				//日期
				laydate.render({
					elem: '#begin'
				});
				laydate.render({
					elem: '#end'
				});
				
				
				//加载条件区的下拉列表
				$.post("selectCondition", {}, function(res) {
					//console.log(res);
					var shtml = "<option></option>";
					$.each(res, function(index, value) {
						//console.log(value);
						shtml += '<option value="' + value.userId + '" > ' + value.userName + '</option>';
					});
					$('#userName').html(shtml);
					form.render('select'); //刷新select选择框渲染
				}, "json");
				//执行一个 table 实例
				table.render({
					elem: '#demo',
					url: '' + globalData.server + 'selectStudentPage', //数据接口,
					method: 'post',
					where: {
						'token': globalData.myToken
					},
					title: '学生表',
					page: true //开启分页
						,
					request: {
						pageName: 'current', //页码的参数名称，默认：page
						limitName: 'size' //每页数据量的参数名，默认：limit
					},
					cols: [
						[ //表头
							{
								type:'checkbox'
							},{
								field: 'studName',
								title: '学生姓名',
								width: 100
							}, {
								field: 'userName',
								title: '咨询师',
								width: 100
							}, {
								field: 'studTel',
								title: '手机号',
								width: 120,
								align: 'center'
							}, {
								field: 'studSex',
								title: '性别',
								width: 80,
								align: 'center'
							}, {
								field: 'studAge',
								title: '年龄',
								width: 80,
								align: 'center'
							}, {
								field: 'studDegree',
								title: '学历',
								width: 80
							}, {
								field: 'studPay',
								title: '是否缴费',
								width: 80
							}, {
								field: 'studPayTime',
								title: '缴费时间',
								width: 180
							}, {
								fixed: 'right',
								title: '操作',
								width: 260,
								align: 'center',
								toolbar: '#barDemo'
							}
						]
					],
					id: "testReload",
					done: function(res, curr, count) {
						loadCurr = false;
					}
				});
				//数据重载
				var $ = layui.$;

				active = {
					reload: function() {
						var studName = $('#studNameC');
						var beginTime = $('#beginTimeC');
						var endTime = $('#endTimeC');
						var studTel = $('#studTelC');
						var studQq = $('#studQqC');
							table.reload('testReload', {
								where: {
									'token': globalData.myToken,
									'studName': studName.val(),
									'beginTime': beginTime.val(),
									'endTime': endTime.val(),
									'studTel': studTel.val(),
									'studQq': studQq.val()
								},
								page: {
									curr: 1 //重新从第 1 页开始			    
								}
							});
						
					}
				};

				//查询操作 
				$('#search').on('click', function() {
					var type = $(this).data('type');
					active[type] ? active[type].call(this) : '';
				});
				var edit_index; //修改弹出窗口的标记，用于关闭

				//监听锁定操作
				form.on('checkbox(lockDemo)', function(obj) {
					var objrow; //监听行操作
					table.on('row(test)', function(obj1) {
						objrow = obj1;
					});
					if(obj.elem.checked) {
						$.post("" + globalData.server + "LockUser", {
							"un": this.value,
							"token": globalData.myToken
						}, function(result) {
							if(result.success) {
								objrow.update({
									IsLockout: '是'
								});
								layer.alert("锁定成功!");
							} else {
								layer.alert(result.message);
							}
						}, "json");
					} else {
						$.post("" + globalData.server + "LockUser", {
							"un": this.value,
							"token": globalData.myToken
						}, function(result) {
							if(result.success) {
								objrow.update({
									IsLockout: '否'
								});
								layer.alert("解锁成功!");
							} else {
								layer.alert(result.message);
							}
						}, "json");
					}
				});
				//监听表单提交
				form.on('submit(userEditBtu)', function(data) {
					$.post("" + globalData.server + "UpdateUser", {
						"userId": data.field.userId,
						"userName": data.field.userName,
						"userEmail": data.field.userEmail,
						"userTel": data.field.userTel,
						"token": globalData.myToken
					}, function(result) {
						if(result.success) {
							layer.msg('修改成功', {
								icon: 1,
								time: 1000
							}, function() {
								window.location.reload();
							});
						} else {
							layer.msg('修改失败', {
								icon: 1,
								time: 2000
							});
						}

					}, "json");
					return false;
				});
				//顶部工具栏事件
				table.on('toolbar(test)', function(obj) {
					switch(obj.event) {
						case 'createUser':
							{
								layer.open({
									type: 1,
									area: ['500px', '400px'],
									title: '添加用户',
									fixed: false, //不固定
									maxmin: true,
									content: $("#user_add")
								});
							}
							break;
					};
				});

				form.on('submit(adduser)', function(data) {
					var str = $("#formCreateUser").serialize() + "&token=" + globalData.myToken;
					$.post("" + globalData.server + "AddUser", str, function(result) {
						if(result.success) {

							layer.msg('添加成功', {
								icon: 1,
								time: 1000
							}, function() {
								window.location.reload();
								parent.layer.close(index);
							});
						} else {
							layer.msg('添加失败', {
								icon: 1,
								time: 2000
							});
						}
					}, "json");
					return false;
				});

				//监听行工具事件
				table.on('tool(test)', function(obj) {
					var data = obj.data;
					//重置密码
					if(obj.event === 'setResetPwd') {
						layer.confirm('确认重置用户' + data.userName + '的密码吗?', function(index) {
							$.post("" + globalData.server + "ResetPwd", {
								"userId": data.userId,
								"token": globalData.myToken
							}, function(result) {
								if(result.success) {
									layer.alert("重置成功!");
								} else {
									layer.alert("重置失败，请重试!");
								}
							}, "json");
						});
					} else if(obj.event === 'setRoleAction') { //角色设置
						//弹出角色设置框	 
						layer.open({
							type: 1,
							title: '您正在设置用户[' + data.userName + ']的角色',
							content: $("#yh_role"),
							area: ['500px', '400px'],
							fixed: false, //不固定
							maxmin: true,
							offset: '10px'
						});
						//左边角色
						$.post(globalData.server + "GetRolesAll", {
							"token": globalData.myToken
						}, function(rean) {
							//var rul = result.map(function(item) {
							//	return {
							//		value: item.roleId,
							//		title: item.roleName

							//	}
							//});

							var rData = new Array(); //定义空数组
							//右边角色  指定角色
							$.post(globalData.server + "GetRolesByUserIdLayUI", {
								"userId": data.userId, //该用户指定id
								"token": globalData.myToken
							}, function(result) { //请求后的回调函数，res--该用户的所有角色的数组
								if(result.count > 0) {
									for(var i = 0; i < result.data.length; i++) {
										rData.push(result.data[i].roleId); //把id全部循环放入到空数组中
									}
								}
								//开始渲染穿梭框
								transfer.render({
									elem: '#role_transfer', //绑定元素
									title: ['系统所有角色', '当前用户角色'],
									data: rean.data,
									value: rData, //用户已有角色
									parseData: function(res) {
										return {
											"value": res.roleId,
											"title": res.roleName

										}
									},
									onchange: function(obj, index) { //如果数据来自左边，index为0，否则为1    onchange相当于一个属性
										if(index == "0") {
											//设置用户角色
											for(var i = 0; i < obj.length; i++) {
												$.post(globalData.server + "AddUserToRole", {
													"userId": data.userId,
													"roleId": obj[i].value,
													"token": globalData.myToken
												}, function(res) {
													if(res.success) {
														layer.msg('添加了', {
															icon: 1,
															time: 1000
														});
													}
												}, "json");
											}
										} else {
											//删除用户角色
											for(var i = 0; i < obj.length; i++) {
												$.post(globalData.server + "RemoveUserFromRole", {
													"userId": data.userId,
													"roleId": obj[i].value,
													"token": globalData.myToken
												}, function(res) {
													if(res.success) {
														layer.msg('移除了', {
															icon: 1,
															time: 1000
														});
													}
												}, "json");
											}
										}
									}

								});
							}, "json");
						}, "json");

					} else if(obj.event === 'setUserDel') { //删除操作
						layer.confirm('确认删除改用户[' + data.userName + ']的信息吗?', function(index) {
							$.post("" + globalData.server + "DeleteUser", {
								"userId": data.userId,
								"token": globalData.myToken
							}, function(result) {
								if(result.success) {
									layer.msg('删除成功', {
										icon: 1,
										time: 1000
									}, function() {
										window.location.reload();
									});
								} else {
									layer.msg('删除失败', {
										icon: 1,
										time: 2000
									});
								}
							}, "json");
						});
					} else if(obj.event === 'setUserEdit') {
						form.val("updateUser", data);
						edit_index = layer.open({
							type: 1,
							title: '您正在修改用户[' + data.userName + ']的信息',
							content: $("#yh_edit"),
							area: ['500px', '400px']
						});
					}
				});

			});
		</script>
	</body>


</html>